(function () {
    $("#loginForm").submit(function () {
        var username = $("input[name='userName']").val();
        var password = $("input[name='password']").val();

        var isSubmiting = false;

        if (!isSubmiting && username !== '' && password !== '') {
            var md5Passwd = md5(password);
            var formParam = {"userName": username, "password": md5Passwd};

            isSubmiting = true;

            $.ajax({
                type: 'post',
                url: '/login',
                data: formParam,
                cache: false,
                dataType: 'json',
                success: function (data) {
                    if (data.result) {
                        window.location.assign("/");
                    } else {
                        alert(data.message);
                    }
                },
                error: function (data) {
                    isSubmiting = false;
                    alert("登录失败,请重试!");
                }
            })
        }
    })
})();
